package com.agadmin.manage.handle.software;

import com.agadmin.api.Api;
import com.agadmin.manage.ManageApiHandle;
import com.agadmin.manage.vo.reponse.software.SoftwareDeleteResponse;
import com.agadmin.manage.vo.request.software.SoftwareDeleteRequest;
import com.agadmin.mapper.SoftwareMapper;
import jakarta.annotation.Resource;

@Api
public class SoftwareDeleteManage implements ManageApiHandle<SoftwareDeleteRequest, SoftwareDeleteResponse> {

    @Resource
    SoftwareMapper softwareMapper;

    @Override
    public SoftwareDeleteResponse handler(SoftwareDeleteRequest softwareDeleteRequest) {
        SoftwareDeleteResponse res = new SoftwareDeleteResponse();
        boolean update = deleteSoft(softwareDeleteRequest);
        if (!update) {
            res.setCode(403);
            res.setError("delete fail,not found soft");
        } else {
            res.setCode(200);
            res.setError("delete successful");
        }
        return res;
    }

    private boolean deleteSoft(SoftwareDeleteRequest req) {
        try {
            int update = softwareMapper.deleteById(req.getId());
            return update > 0;
        } catch (Exception e) {
            return false;
        }
    }

}
